package com.lovo.pis.utils;

import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

public class FileUtil {

    public static String getFileName(MultipartFile file){

        String fileName= file.getOriginalFilename();
        String suffixName = fileName.substring(fileName.lastIndexOf("."));
        String newName = UUID.randomUUID()+suffixName;
        try {
            file.transferTo(new File("d:/image/"+newName));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return newName;
    }
    public static String getFilePathName(MultipartFile file){

        String fileName= file.getOriginalFilename();
        String suffixName = fileName.substring(fileName.lastIndexOf("."));
        String newName = UUID.randomUUID()+suffixName;
        String pathName ="d:/excel/"+newName;
        try {
            file.transferTo(new File(pathName));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return pathName;
    }
}
